package com.baizhi.service.impl;

import com.baizhi.dao.ProductDao;
import com.baizhi.entity.Product;
import com.baizhi.service.ProductService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductDao productDao;
    @Override
    public void insert(Product product) {
        productDao.insert(product);
    }

    @Override
    public void delete(Integer pid) {
        productDao.delete(pid);
    }

    @Override
    public void deleteAny(Integer[] pids) {
        productDao.deleteAny(pids);
    }

    @Override
    public void update(Product product) {
        productDao.update(product);
    }

    @Override
    @Transactional(readOnly = true)
    public Product selectById(Integer pid) {
        return productDao.selectById(pid);
    }

    @Override
    @Transactional(readOnly = true)
    public PageInfo<Product> selectByPage(String pname, Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        PageInfo<Product> pageInfo = new PageInfo<>(productDao.selectByPage(pname));
        return pageInfo;
    }
}
